package com.domino.shared;

import java.io.Serializable;
import java.util.List;

import com.domino.shared.model.Brick;
import com.domino.shared.model.Color;
import com.domino.shared.session.SessionId;

public abstract class SessionStateResponse implements Serializable {

	/*
	 * TODO: replace with enum
	 */
	private int state;
	public static final int CLIENT_ACTION = 0;
	public static final int WAIT_FOR_SERVER = 1;
	public static final int GAME_FINISHED = 2;
	public static final int WAIT_FOR_OPPONENT_TO_JOIN = 3;
	public static final int RECOVERING = 4;
	public static final int WAIT_OPPONENT_ACTION = 5;
	public static final int PLAYER_GAVE_UP = 6;
	private static final String[] STATUS = {"CLIENT_ACTION","WAIT_FOR_SERVER","GAME_FINISHED","WAIT_FOR_OPPONENT_TO_JOIN", 
											"RECOVERING", "WAIT_OPPONENT_ACTION", "PLAYER_GAVE_UP"};

	private SessionStateResponse() {
		this(-1);
	}
	
	protected SessionStateResponse(int state) {
		this.state = state;
	}

	private String decode(int state) {
		return STATUS[state];
	}
	
	public boolean makeAMove() {
		return state == CLIENT_ACTION;
	}

	public boolean isFinished() {
		return state == GAME_FINISHED && (getMoves()==null || getMoves().isEmpty());
	}
	
	public int getState() {
		return state;
	}
	
	public Player getPlayer() {
		return null;
	}

	public Player getOpponent() {
		return null;
	}

	public List<Brick> getMoves() {
		return null;
	}
	
	public SessionId getSessionId() {
		return null;
	}
	
	public Color getColor() {
		return null;
	}

	@Override
	public String toString() {
		return "SessionStateResponse [sessionId=" + getSessionId() + " state=" + decode(state) + " opponent=" + getOpponent() + " moves=" + getMoves() + " color=" + getColor() + "]";
	}

	public boolean recoveringFromError() {
		return state==RECOVERING;
	}

	public boolean waitForServer() {
		return state==WAIT_FOR_OPPONENT_TO_JOIN || state==WAIT_FOR_SERVER;
	}
	
	public boolean waitForOppponentAction() {
		return state==WAIT_OPPONENT_ACTION;
	}
	public String getDebugMessage() {
		return null;
	}
	public Color getGivingUpColor() {
		return null;
	}
	

}